package com.yanqu.road.entity.union;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public class UnionMember extends DataObject {

	private String unionUid;

	private long userId;

	private int position;                //职位

	private UserBaseInfo userBaseInfo = new UserBaseInfo();

	private long modifyTime;

	private long contribution;                 //贡献

	private long totalContribution;            //总贡献

	private int donateTimes;                   //捐赠次数

	private long quitTime;                     //退出家族时间

	private long kickTime;                      //被踢时间

	private long joinTime;                      //加入时间

	private int dayKickNum;            //当天踢人人数

	private List<String> applyUnionUidList = new ArrayList<>();     //申请加入联盟列表

	private Map<Integer, UnionConstruct> unionConstructMap = new ConcurrentHashMap<>();       //当天建设数据

	private List<Integer> constructRewardIndexList = new ArrayList<>();

	private int todayContribution;

	private int chamberPatronsId;

	@Deprecated
	private UserPatrons chamberPatron;

	private int noticeReadState;     //公告阅读状态

	private boolean dayCoolingOffNotice;	//每日冷静期通知

	private BigInteger historyMaxAbility = BigInteger.ZERO;	//历史最高门客赚钱和

	private int monthAbilityRank;//最高赚钱实力评定排行
	private int abilityRankGrade;//最高赚钱实力档位

	//缓存重置前贡献
	private int cacheTodayContribution;

	public String getUnionUid() {
		return unionUid;
	}

	public void setUnionUid(String unionUid) {
		if(!Objects.equals(this.unionUid, unionUid)) {
			this.unionUid = unionUid;
			setUpdateOption();
		}
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		if(this.userId != userId) {
			this.userId = userId;
			setUpdateOption();
		}
	}

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		if(this.position != position) {
			this.position = position;
			setUpdateOption();
		}
	}

	public UserBaseInfo getUserBaseInfo() {
		return userBaseInfo;
	}

	public String getUserBaseInfoJsonStr(){
		if(null == userBaseInfo){
			return "{}";
		}else {
			return JSON.toJSONString(userBaseInfo);
		}
	}

	public void setUserBaseInfo(UserBaseInfo userBaseInfo) {
		this.userBaseInfo = userBaseInfo;
		setUpdateOption();
	}

	public long getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(long modifyTime) {
		if(this.modifyTime != modifyTime) {
			this.modifyTime = modifyTime;
			setUpdateOption();
		}
	}

	public long getContribution() {
		return contribution;
	}

	public void setContribution(long contribution) {
		if(this.contribution != contribution) {
			this.contribution = contribution;
			setUpdateOption();
		}
	}

	public long getTotalContribution() {
		return totalContribution;
	}

	public void setTotalContribution(long totalContribution) {
		if(this.totalContribution != totalContribution) {
			this.totalContribution = totalContribution;
			setUpdateOption();
		}
	}

	public int getDonateTimes() {
		return donateTimes;
	}

	public void setDonateTimes(int donateTimes) {
		if(this.donateTimes != donateTimes) {
			this.donateTimes = donateTimes;
			setUpdateOption();
		}
	}

	public long getQuitTime() {
		return quitTime;
	}

	public void setQuitTime(long quitTime) {
		if(this.quitTime != quitTime) {
			this.quitTime = quitTime;
			setUpdateOption();
		}
	}

	public long getKickTime() {
		return kickTime;
	}

	public void setKickTime(long kickTime) {
		if(this.kickTime != kickTime) {
			this.kickTime = kickTime;
			setUpdateOption();
		}
	}

	public long getJoinTime() {
		return joinTime;
	}

	public void setJoinTime(long joinTime) {
		if(this.joinTime != joinTime) {
			this.joinTime = joinTime;
			setUpdateOption();
		}
	}

	public int getTodayContribution() {
		return todayContribution;
	}

	public void setTodayContribution(int todayContribution) {
		if(this.todayContribution != todayContribution) {
			this.todayContribution = todayContribution;
			setUpdateOption();
		}
	}

	public int getChamberPatronsId() {
		return chamberPatronsId;
	}

	public void setChamberPatronsId(int chamberPatronsId) {
		if(this.chamberPatronsId != chamberPatronsId) {
			this.chamberPatronsId = chamberPatronsId;
			setUpdateOption();
		}
	}

	@Deprecated
	public UserPatrons getChamberPatron() {
		return chamberPatron;
	}

	@Deprecated
	public void setChamberPatron(UserPatrons chamberPatron) {
		this.chamberPatron = chamberPatron;
	}

	public void setApplyUnionUidList(List<String> applyUnionUidList) {
		this.applyUnionUidList = applyUnionUidList;
	}

	public String getApplyUnionUidListString(){
		return StringUtils.listToString(applyUnionUidList, ',');
	}

	public void addApplyUnionUid(String unionUid){
		if(!hasApplyUnionUid(unionUid)){
			applyUnionUidList.add(unionUid);
		}
	}

	public void removeApplyUnionUid(String unionUid){
		if(applyUnionUidList.contains(unionUid)){
			applyUnionUidList.remove(unionUid);
		}
	}

	public boolean hasApplyUnionUid(String unionUid){
		return applyUnionUidList.contains(unionUid);
	}

	public void setUnionConstructMap(Map<Integer, UnionConstruct> unionConstructMap) {
		this.unionConstructMap = unionConstructMap;
		setUpdateOption();
	}

	public String getUnionConstructMapJson(){
		return JSON.toJSONString(unionConstructMap);
	}

	public void addConstructTimes(int constructType){
		UnionConstruct unionConstruct = getUnionConstruct(constructType);
		if(null == unionConstruct){
			unionConstruct = new UnionConstruct();
			unionConstruct.setConstructType(constructType);
			unionConstruct.setTimes(1);
			unionConstruct.setLastConstructTime(System.currentTimeMillis() / 1000);
			unionConstructMap.put(unionConstruct.getConstructType(), unionConstruct);
		}else {
			unionConstruct.setTimes(unionConstruct.getTimes() + 1);
			unionConstruct.setLastConstructTime(System.currentTimeMillis() / 1000);
		}
		setUpdateOption();
	}

	private UnionConstruct getUnionConstruct(int constructType){
		return unionConstructMap.get(constructType);
	}

	public int getConstructTimes(int constructType){
		UnionConstruct unionConstruct = getUnionConstruct(constructType);
		if(null != unionConstruct){
			return unionConstruct.getTimes();
		}
		return 0;
	}

	public long getLastConstructTime(int constructType){
		UnionConstruct unionConstruct = getUnionConstruct(constructType);
		if(null != unionConstruct){
			return unionConstruct.getLastConstructTime();
		}
		return 0;
	}

	public void setConstructRewardIndexList(List<Integer> constructRewardIndexList) {
		this.constructRewardIndexList = constructRewardIndexList;
		setUpdateOption();
	}

	public String getConstructRewardIndexListString(){
		return StringUtils.listToString(constructRewardIndexList, ',');
	}

	public void addConstructRewardIndex(int rewardIndex){
		if(!hasConstructRewardIndex(rewardIndex)){
			constructRewardIndexList.add(rewardIndex);
			setUpdateOption();
		}
	}

	public boolean hasConstructRewardIndex(int rewardIndex){
		return constructRewardIndexList.contains(rewardIndex);
	}

	public int getNoticeReadState() {
		return noticeReadState;
	}

	public void setNoticeReadState(int noticeReadState) {
		if(this.noticeReadState != noticeReadState) {
			this.noticeReadState = noticeReadState;
			setUpdateOption();
		}
	}

	public Map<Integer, UnionConstruct> getUnionConstructMap() {
		return unionConstructMap;
	}

	public int getDayKickNum() {
		return dayKickNum;
	}

	public void setDayKickNum(int dayKickNum) {
		if(this.dayKickNum != dayKickNum) {
			this.dayKickNum = dayKickNum;
			setUpdateOption();
		}
	}

	public boolean getDayCoolingOffNotice() {
		return dayCoolingOffNotice;
	}

	public void setDayCoolingOffNotice(boolean state) {
		if(this.dayCoolingOffNotice != state) {
			this.dayCoolingOffNotice = state;
			setUpdateOption();
		}
	}

	public BigInteger getHistoryMaxAbility() {
		return historyMaxAbility;
	}

	public void setHistoryMaxAbility(BigInteger historyMaxAbility) {
		if (this.historyMaxAbility != historyMaxAbility){
			this.historyMaxAbility = historyMaxAbility;
			setUpdateOption();
		}
	}

	public int getMonthAbilityRank() {
		return monthAbilityRank;
	}

	public void setMonthAbilityRank(int monthAbilityRank) {
		if (this.monthAbilityRank != monthAbilityRank){
			this.monthAbilityRank = monthAbilityRank;
			setUpdateOption();
		}
	}

	public int getAbilityRankGrade() {
		return abilityRankGrade;
	}

	public void setAbilityRankGrade(int abilityRankGrade) {
		if (this.abilityRankGrade != abilityRankGrade) {
			this.abilityRankGrade = abilityRankGrade;
			setUpdateOption();
		}
	}

	public int getCacheTodayContribution() {
		return cacheTodayContribution;
	}

	public void setCacheTodayContribution(int cacheTodayContribution) {
		this.cacheTodayContribution = cacheTodayContribution;
	}
}